AltME groups: search
Help · search scripts · search articles · search mailing listresults summary
world | hits |
r4wp | 18 |
r3wp | 193 |
total: | 211 |
results window for this page: [start: 1 end: 100]
world-name: r4wp
Group: Rebol School ... REBOL School [web-public] | ||
Gregg: 24-Apr-2012 | parse-int-values: func [ "Parses and returns integer values, each <n> chars long in a string." input [any-string!] spec [block!] "Dialected block of commands: <n>, skip <n>, done, char, or string" /local gen'd-rules ; generated rules result ; what we return to the caller emit emit-data-rule emit-skip-rule emit-literal-rule emit-data digit= n= literal= int-rule= skip-rule= literal-rule= done= build-rule= data-rule skip-rule ][ ; This is where we put the rules we build; our gernated parse rules. gen'd-rules: copy [] ; This is where we put the integer results result: copy [] ; helper functions emit: func [rule n] [append gen'd-rules replace copy rule 'n n] emit-data-rule: func [n] [emit data-rule n] emit-skip-rule: func [n] [emit skip-rule n] emit-literal-rule: func [value] [append gen'd-rules value] emit-data: does [append result to integer! =chars] ; Rule templates; used to generate rules ;data-rule: [copy =chars n digit= (append result to integer! =chars)] data-rule: [copy =chars n digit= (emit-data)] skip-rule: [n skip] ; helper parse rules digit=: charset [#"0" - #"9"] n=: [set n integer!] literal=: [set lit-val [char! | any-string!]] ; Rule generation helper parse rules int-rule=: [n= (emit-data-rule n)] skip-rule=: ['skip n= (emit-skip-rule n)] literal-rule=: [literal= (emit-literal-rule lit-val)] done=: ['done (append gen'd-rules [to end])] ; This generates the parse rules used against the input build-rule=: [some [skip-rule= | int-rule= | literal-rule=] opt done=] ; We parse the spec they give us, and use that to generate the ; parse rules used against the actual input. If the spec parse ; fails, we return none (maybe we should throw an error though); ; if the data parse fails, we return false; otherwise they get ; back a block of integers. Have to decide what to do if they ; give us negative numbers as well. either parse spec build-rule= [ either parse input gen'd-rules [result] [false] ] [none] ] | |
Ladislav: 19-Jun-2012 | If you do want to leave out the </br> and </div> substrings, the simplest way probably is: s1: "a http://xxx</div>b http://yyy</br>" parse/all s1 [any [to "http://"start: any [end: </br> break | </div> break | skip] (print copy/part start end)]] | |
Ladislav: 21-Jun-2012 | Finally, which is the purpose of the SKIP keywork in this context ? - that is the easiest question. The expression any [end: </div> break | </br> break | skip] simply checks whether it "sees" the </div> terminator. If it does then the search for the terminator is over. If it does not then we check immediately whether we do not "see" the second possible terminator. However, if we are not at the terminator, both alternatives fail and the third alternative has to advance to the next position to be able to finally find the terminator. | |
Ladislav: 21-Jun-2012 | This may be a simpler/more understandable description of the idea: terminator: [</div> | </br>] find-terminator: [start: any [end: terminator break | skip] (contents: copy/part start end)] | |
DocKimbel: 8-Aug-2012 | Here's a R2 solution with same rules for string! and block! series: rle: func [s [series!] /local out c i][ out: make block! 1 parse/case/all s [ any [ [end | c: ( c: either word? c/1 [to-lit-word c/1][c/1] i: 1 )] skip some [ c (i: i + 1) | (repend out [i c]) break ] ] ] out ] >> rle "aaabbcx" == [3 #"a" 2 #"b" 1 #"c" 1 #"x"] >> rle [a a a a a] == [5 a] >> rle [a a a a a b b] == [5 a 2 b] >> rle [a a A b b c d D d d d] == [3 a 2 b 1 c 5 d] | |
DocKimbel: 8-Aug-2012 | Another version of 'rle for R2 that uses two pointers (like your R3 version) instead of a counter: rle: func [s [series!] /local out c pos1 pos2][ out: make block! 1 parse/case/all s [ any [ [end | c: ( c: either word? c/1 [to-lit-word c/1][c/1] )] pos1: skip some [c | pos2: (repend out [offset? pos1 pos2 c]) break] ] ] out ] | |
BrianH: 8-Aug-2012 | The replacement for IF (condition) would be something like this: (cont: unless condition [[end skip]]) cont | |
BrianH: 8-Aug-2012 | Here's a version of Doc's with all datatypes handled, even unset. It even avoids accidentally converting lit-words to words and lit-paths to paths: rle: func [s [series!] /local out pos1 pos2 cont][ out: make block! 1 parse/all s [ any [ pos1: skip some [ pos2: skip (cont: if any [ not-equal? unset? :pos1/1 unset? :pos2/1 strict-not-equal? :pos1/1 :pos2/1 ] [[end skip]]) cont | pos2: (repend out [offset? :pos1 :pos2 :pos1/1]) break ] ] ] out ] | |
BrianH: 8-Aug-2012 | This version handles unsets too: rle: func [s [series!] /local out emit pos1 pos2 cont][ out: make block! 1 emit: [(repend out [offset? :pos1 :pos2 :pos1/1])] parse/all s [ any [ pos1: unset! some [pos2: unset! | pos2: emit break] | pos1: skip some [ pos2: unset! :pos2 emit break | pos2: skip ( cont: if strict-not-equal? :pos1/1 :pos2/1 [[end skip]] ) cont | pos2: emit break ] ] ] out ] | |
BrianH: 8-Aug-2012 | Slight improvement: rle: func [s [series!] /local out emit pos1 pos2 cont][ out: make block! 1 emit: [(repend out [offset? :pos1 :pos2 :pos1/1])] parse/all s [any [ pos1: unset! any unset! pos2: emit | pos1: skip some [ pos2: unset! :pos2 emit break | pos2: skip ( cont: if strict-not-equal? :pos1/1 :pos2/1 [[end skip]] ) cont | pos2: emit break ] ]] out ] | |
BrianH: 9-Aug-2012 | Two rules it is then. This doesn't crash, and is optimized for strings while we're at it. It's probably slower when doing blocks than Doc's, but it handles all datatypes: rle: func [s [series!] /local out emit pos1 pos2 cont][ out: make block! 1 emit: [(repend out [offset? :pos1 :pos2 first :pos1])] parse/case/all :s pick [[ any [pos1: skip (cont: first :pos1) any cont pos2: emit] ] [ any [ pos1: unset! any unset! pos2: emit | pos1: skip some [ end pos2: emit break | pos2: unset! :pos2 emit break | pos2: skip ( cont: unless strict-equal? first :pos1 first :pos2 [[end skip]] ) cont | pos2: emit break ] ] ]] any-string? :s out ] It also works around the strict-not-equal? bug in pre-2.7.7 R2, and using FIRST instead of path access is another speedup in R2 (path access is faster in R3). | |
BrianH: 9-Aug-2012 | Change the repend to chained inserts and it gets noticably faster, due to less mezzanine overhead: rle: func [s [series!] /local out emit pos1 pos2 cont][ out: make block! 2 emit: [(out: insert/only insert out offset? :pos1 :pos2 first :pos1)] parse/case/all :s pick [[ any [pos1: skip (cont: first :pos1) any cont pos2: emit] ] [ any [ pos1: unset! any unset! pos2: emit | pos1: skip some [ end pos2: emit break | pos2: unset! :pos2 emit break | pos2: skip ( cont: unless strict-equal? first :pos1 first :pos2 [[end skip]] ) cont | pos2: emit break ] ] ]] any-string? :s head out ] | |
BrianH: 9-Aug-2012 | If you follow the /into option standard you can do chained calls to RLE too: rle: func [s [series!] /into out [any-block!] /local emit pos1 pos2 cont][ unless into [out: make block! 2] emit: [(out: insert/only insert :out offset? :pos1 :pos2 first :pos1)] parse/case/all :s pick [[ any [pos1: skip (cont: first :pos1) any cont pos2: emit] ] [ any [ pos1: unset! any unset! pos2: emit | pos1: skip some [ pos2: unset! :pos2 emit break | pos2: skip ( cont: unless strict-equal? first :pos1 first :pos2 [[end skip]] ) cont | pos2: emit break ] ] ]] any-string? :s either into [:out] [head :out] ] | |
BrianH: 11-Aug-2012 | Steeve, that's basically the same as my R2 RLE's block rule, but with the IF workaround replaced with IF. It has a few gotchas: - Executes function values in block data - Doesn't handle unset! or error! values - Converts lit-paths to paths and lit-words to words before comparison and again before putting in the output. - Lots of intermediate block creation overhead - Considers bindings of words when comparing them, not just case-sensitive spelling The first 3 can be handled by using :p/1 and :e/1 instead of p/1 and e/1, and the fourth by using REDUCE/into instead of REPEND. The last one can't be handled by any built-in function or operator in R3 (see http://issue.cc/r3/1834for details) but you could do a combination of functions and operators to get case-sensitive comparison without considering bindings. PARSE/case's QUOTE operation is the fastest method for doing that at the moment. Nice job on neatly bypassing the relaxed bounds checking of R3 blocks. Though the if (p/1 == e/1) would succeed if p/1 is none and e is at the end of the block, the skip would still fail. That trick saves one e: operation. | |
Gregg: 28-May-2013 | parse-int-values: func [ "Parses and returns integer values, each <n> chars long in a string." input [any-string!] spec [block!] "Dialected block of commands: <n>, skip <n>, done, char, or string" /local gen'd-rules ; generated rules result ; what we return to the caller emit emit-data-rule emit-skip-rule emit-literal-rule emit-data digit= n= literal= int-rule= skip-rule= literal-rule= done= build-rule= data-rule skip-rule ][ ; This is where we put the rules we build; our gernated parse rules. gen'd-rules: copy [] ; This is where we put the integer results result: copy [] ; helper functions emit: func [rule n] [append gen'd-rules replace copy rule 'n n] emit-data-rule: func [n] [emit data-rule n] emit-skip-rule: func [n] [emit skip-rule n] emit-literal-rule: func [value] [append gen'd-rules value] emit-data: does [append result to integer! =chars] ; Rule templates; used to generate rules ;data-rule: [copy =chars n digit= (append result to integer! =chars)] data-rule: [copy =chars n digit= (emit-data)] skip-rule: [n skip] ; helper parse rules digit=: charset [#"0" - #"9"] n=: [set n integer!] literal=: [set lit-val [char! | any-string!]] ; Rule generation helper parse rules int-rule=: [n= (emit-data-rule n)] skip-rule=: ['skip n= (emit-skip-rule n)] literal-rule=: [literal= (emit-literal-rule lit-val)] done=: ['done (append gen'd-rules [to end])] ; This generates the parse rules used against the input build-rule=: [some [skip-rule= | int-rule= | literal-rule=] opt done=] ; We parse the spec they give us, and use that to generate the ; parse rules used against the actual input. If the spec parse ; fails, we return none (maybe we should throw an error though); ; if the data parse fails, we return false; otherwise they get ; back a block of integers. Have to decide what to do if they ; give us negative numbers as well. either parse spec build-rule= [ either parse input gen'd-rules [result] [false] ] [none] ] | |
Group: !REBOL3 ... General discussion about REBOL 3 [web-public] | ||
GrahamC: 9-Jan-2013 | digit: charset [ #"0" - #"9" ] alpha: charset [ #"a" - #"z" #"A" - #"Z" ] idate-to-date: func [ date [string!] /local day month year zone] [ either parse date [ 5 skip copy day 2 digit space copy month 3 alpha space copy year 4 digit space copy time to space space copy zone to end ][ if zone = "GMT" [ zone: copy "+0" ] to date! rejoin [ day "-" month "-" year "/" time zone ] ][ none ] ] if headers/last-modified [info/date: attempt [ idate-to-date headers/last-modified] ] seems to work | |
Gregg: 15-Mar-2013 | Good catch. I just added series support, and since it's a simple dialect, it won't like that. In the current version, you would have to use an interim var for 'end. e.g.: >> b: (skip ser 6) == [7] >> loop compose [v ser b 2] [print v] | |
Geomol: 30-May-2013 | Something like: out: clear "" script: { for /*(set)*/ myvar /*starting from*/ 1 /*reach*/ 10 /*use the stepping*/ 2 /* and execute*/ [ print myvar ] } parse script [some [ copy s to "/*" (append out s) thru "*/" | copy s to end (append out s) 1 skip ]] do out |
world-name: r3wp
Group: RAMBO ... The REBOL bug and enhancement database [web-public] | ||
Pekr: 1-Dec-2005 | Chris - maybe it should, if you look at how skip "" 5 works. 'skip operation here is simply kind of doing "nothing" - trying to jump, but already at the end, so it jumps nowhere :-) | |
Brett: 2-Dec-2005 | >> parse {ab} [to {a} to {a} to {a} to {a} {b}] == false >> parse {ab} [to #"a" skip #"b"] == true >> parse {ab} [to #"a" to #"a" to #"a" skip #"b"] == true >> parse {ab} [to #"a" to #"a" to #"a" to #"a" skip #"b"] == true >> parse {12345} [to end to end to end to end] == true >> parse {12345} [to end to 6 to 10 to 100 to end] == true >> parse {123} [thru 4 (print 1)] == false >> parse {123} [to 5 skip] == false | |
Ladislav: 19-Apr-2006 | this is the way: parse [/] [set w word! (nx: unless w = first [/] [[end skip]]) nx] | |
Anton: 23-Nov-2006 | switch: func [ "Selects a choice and evaluates the first block that follows it." [throw] ; <-- allows RETURN to be used by the user to jump out of an enclosing function (not just this one) value "Value to search for." cases [block!] "Block of cases to search." /default case [block!] "Default case if no others are found." /all "Evaluate all matches (not just first one)" /local rule new ][ rule: [ 1 1 () ; <-- value to block! set new block! ; <- re-use the 'case variable ( if any [default none? case][default: none case: clear []] ; only clear case the first time append case new ) to end ; <-- | skip to () ; <-- type? value ] rule/3: value change back tail rule type? value rule/11: either all [type? value]['end] parse cases [some rule] do case ] | |
Group: Core ... Discuss core issues [web-public] | ||
JaimeVargas: 7-Apr-2005 | I hope this is useful for someone REBOL [] rest: func [s [series!]][skip s 1] define-object: func [ spec [block!] /local arg-spec ctx-spec object-name constructor-name predicate-name attributes spec-rule type-spec continue? w ][ arg-names: copy [] continue?: [none] ;used to stop parsing name-rule: [set w word! (insert tail arg-names w)] type-rule: [set w word! (unless datatype? attempt [get w] [continue?: [end skip]])] spec-rule: [name-rule some [name-rule opt [into [some [type-rule continue?]]]]] if any [ not parse spec spec-rule arg-names <> unique arg-names ][ make error! "invalid spec" ] object-name: to-string first arg-names constructor-name: to-word join 'make- object-name predicate-name: to-word join first arg-names '? attributes: rest arg-names arg-spec: copy [] foreach itm attributes [ insert tail arg-spec reduce [ to-word join itm '-value either block? w: select spec itm [w][[any-type!]] ] ] ctx-spec: copy [] arg-names: extract arg-spec 2 1 repeat i length? attributes [ insert tail ctx-spec reduce [to-set-word attributes/:i to-get-word arg-names/:i] ] ;create constructor function set constructor-name make function! compose [(reform ["Makes a new" uppercase object-name "object with attributes" mold attributes]) (arg-spec)] compose/only [make object! (ctx-spec)] ;body ;create predicate function set predicate-name make function! compose [(reform ["Determines if value is a" uppercase object-name "object"]) value [object!] /local types] compose/deep/only [ either (attributes) = rest first value [ foreach itm (attributes) [ unless any [ [any-type!] = types: select (arg-spec) to-word join itm '-value find types type?/word value/:itm ][return false] ] true ][ false ] ] ] | |
JaimeVargas: 7-Apr-2005 | If anyone ever wanted multi-methods or function overload in rebol here is the answer. Enjoy ;-) REBOL [] define-method: func [ 'name [word!] spec [block!] locals [block!] code [block!] /local w type-rule spec-rule continue? register-name methods-name ][ ;; first validate the spec continue?: [none] ;used to stop parsing type-rule: [set w word! (unless datatype? attempt [get w] [continue?: [end skip]])] spec-rule: [some [word! into [type-rule continue?]]] unless parse spec spec-rule [make error! "invalid spec"] register-name: to-word join :name '-register methods-name: to-word join :name '-methods? unless value? name [ context [ dispatch-table: copy [] spec-fingerprint: func [spec [block!] /local types][ types: copy [] foreach itm extract/index spec 2 2 [insert tail types itm/1 ] types ] values-fingerprint: func [values [block!] /local types][ types: copy [] foreach v values [insert tail types type?/word v] types ] retrieve-func: func [values [block!]][select/only dispatch-table values-fingerprint values] set :name func [values [block!]][ do compose [(retrieve-func values) (values)] ] set :register-name func [spec code /local fingerprint pos][ fingerprint: spec-fingerprint spec either found? pos: find/only dispatch-table fingerprint [ poke dispatch-table 1 + index? pos function spec locals code ][ insert tail dispatch-table reduce [fingerprint function spec locals code] ] ] set :methods-name does [probe dispatch-table] ] ] do reduce [register-name spec code] ] define-method f [x [integer!]] [] [x + 1] define-method f [s [block!]] [] [attempt [pick s 2]] define-method f [x [decimal!]] [] [sine x] f[5] == 6 f[[one two three]] == two f[90.0] == 1.0 | |
Group: I'm new ... Ask any question, and a helpful person will try to answer. [web-public] | ||
DideC: 22-Jun-2005 | >> help new-line USAGE: NEW-LINE block value /all /skip size DESCRIPTION: Sets or clears the new-line marker within a block. NEW-LINE is a native value. ARGUMENTS: block -- Position in block to change marker (Type: block) value -- Set TRUE for newline. (Type: any) REFINEMENTS: /all -- Set/clear marker to end of block /skip -- Set/clear marker periodically to the end of the block size -- (Type: integer) >> a: [1 2 3 4 5 6 7 8 9 10] == [1 2 3 4 5 6 7 8 9 10] >> new-line a true == [ 1 2 3 4 5 6 7 8 9 10 ] >> new-line a false == [1 2 3 4 5 6 7 8 9 10] >> new-line/skip a true 2 == [ 1 2 3 4 5 6 7 8 9 10 ] | |
Anton: 14-Apr-2006 | page: read http://www.rebol.com images: copy [] use [whsp ws non-end-tag strd p1 p2 delim non-delim][ whsp: charset " ^-^/" ; whitespace ws: [any whsp] ; a rule for any number of whitespace characters non-end-tag: complement charset ">" ; all characters except ">" strd: charset {"'} ; string delimiters, double and single quote parse/all page [ any [ thru "<img" [ ws "src" ws "=" ws p1: [strd (delim: form p1/1) | (delim: ">")] (non-delim: complement union whsp charset delim) p1: any non-delim p2: (append images copy/part p1 p2) ; keep the url | non-end-tag ] | skip ] ] ] new-line/all images on ; add hidden newlines to the images block so it molds nicely print mold images | |
Anton: 14-Apr-2006 | page: read http://www.rebol.com images: copy [] use [whsp ws non-end-tag strd p1 p2 delim non-delim][ whsp: charset " ^-^/" ; whitespace ws: [any whsp] ; a rule for any number of whitespace characters non-end-tag: complement charset ">" ; all characters except ">" strd: charset {"'} ; string delimiters, double and single quote parse/all page [ any [ thru "<img" whsp [ any [ ws "src" ws "=" ws p1: [strd (delim: form p1/1) | (delim: ">")] (non-delim: complement union whsp charset delim) p1: any non-delim p2: (append images copy/part p1 p2) ; keep the url | non-end-tag ] ] | skip ] ] ] new-line/all images on ; add hidden newlines to the images block so it molds nicely print mold images | |
Anton: 14-Apr-2006 | page: read http://www.rebol.com ; special test cases from Alek_K ;page: {<img src="one two.jpg">} ; OK ;page: {<img alt="picture" src=one.jpg />} ; OK images: copy [] use [whsp ws non-end-tag strd wh- non-str-delim p1 p2 delim non-delim][ whsp: charset " ^-^/" ; whitespace ws: [any whsp] ; a rule for any number of whitespace characters non-end-tag: complement charset ">" ; all characters except ">" strd: charset {"'} ; string delimiters, double and single quote wh-: charset "^-^/" ; whitespace minus the space character (space is allowed inside a quoted string) non-str-delim: complement union whsp charset ">" parse/all page [ any [ thru "<img" whsp [ any [ ws "src" ws "=" ws ;p1: [strd (delim: form p1/1) | (delim: ">")] (non-delim: complement union whsp charset delim) p1: [strd (non-delim: complement union wh- charset form p1/1) | (non-delim: non-str-delim)] p1: any non-delim p2: (append images copy/part p1 p2) ; keep the url | non-end-tag ] ] | skip ] ] ] new-line/all images on ; add hidden newlines to the images block so it molds nicely print mold images | |
BrianH: 17-Jan-2008 | If you want to do keyword-based records, put the keywords and values in the same block and use select/skip data key 2 Put each record in its own block: with variable length records you will need to track the end of the record otherwise. This method will be slower, but take less space when at least half of the fields are usually missing. | |
sqlab: 14-Apr-2009 | better rule: [(wanted: copy [] ) any [to "wanted" copy line to "rubbish" (append wanted line) skip ] to end] | |
PeterWood: 15-Apr-2009 | In case this isn't clear. I'll try to explain the parse rule. First any effectively says to match any of the rules in the following block until the end of the string is reached. The first rule in the block is [interface copy int-text some name-char (print ["interface: " int-text)] says match with the word interface (newline + "interface ") then if there is a match, copy some name-char which says copy one or more characters which match the criteria of a name-char then if there are some name-char characters evaluate the rebol code in parentheses. If there wasn't a match with that first rule, then the second rule that follows the | will be applied. skip will pass over one character and always provides a match. | |
PeterWood: 16-Apr-2009 | Mike - The method that I showed you does not use up the "newline" at the end of the line. If you check again, the parse rule simply says copy in-text some name-char. This "stops" before the newline at the end of the line. In fact guessing at your requirements a little and assuming the name-char is available. Some thing along these lines should be close to what you want: keywords: ["^/interface " | "^/another keyword " | "^/yet another kerword"] parse/all lines [any [ copy int-keyword [keywords copy int-text some name-char ( print int-keyword ": " int-text] ) | skip ] ] {I obviously haven't tested this code.) | |
mhinson: 16-Apr-2009 | The mist maybe slowly clearing (sorry to be so slow to catch on). The 2 stage process may be the answer, perhaps I can add a key char at the first line position when I read the file, then use this as the line start reference, but continue to use the end of line as normal. I think I understand Peter's example & have tweaked it a bit to make it work for me. lines: {~junk Interface fa0 ~! ~interface fa1 ~interface fa2 point-to-point ~! ~interface Fa3 ~ description test three ~ ip address 1.1.3.3 255.255.255.0 ~! ~interface Fa4 ~ ip address 1.1.4.4 255.255.255.0 ~! ~interface Fa3 ~ description test four etc ~} spacer: charset "^/" name-char: complement spacer stopwords: "point-to-point" keywords: ["~interface " | "~ description " | "~ ip address"] parse/all lines [any [ copy int-keyword keywords copy int-text [to stopwords | some name-char] ( print [int-keyword ": " int-text] ) | skip ] ] | |
mhinson: 17-Apr-2009 | I have been studying the code from sqlab but I cant understand it enough to modify it. This is a deconstruction of part of it with my comments added. I would love a hand to understand this a bit more. I cant find any documentation for this sort of thing that I can understand. I have also been trying to retrieve an index number when reading lines so it can be used as suggested by Sunanda. drawn a blank so far. parse/all lines [ ;; parse the whole block called lines /all makes parsing only use values given below ;; I am not sure if this is itteratied or the whole block parsed as one. (wanted: copy []) ;; initalise wanted | some [ ;; one or more matches needed to return true ifa: "interface" some [ ;; ifa is given a string value right in the middle of the parsing code ;; I see why, but not how this is able to slip into the middle here ;; then some starts another block so perhaps the "interface" is used by parse too?? ife: "point-to-point" break ;; no idea how the syntax works here | ife: newline break ;; or here | skip ;; this skips I think till one of the OR conditions are met from below? ] (append/only append wanted copy/part ifa ife interf: copy []) ;; I dont understand what block append/only is working on here ;; append to block wanted using a part copy between ifa & ife but I ;; dont understand the source for the copy | some [ ;; I think perhaps all the below rules are end or search paterns? s: " interface" (interf: copy []) | drule | iprule | norule | pvcrul | pprule | !rule | break ] thru newline ;; final catchall end search pattern. ] ] Sorry to ask so many questions, feel free to throw me out if this is just too much, but I have spent several hours on this fragment allready. Thanks. | |
Oldes: 17-Apr-2009 | parse/all {ab hello cd} [3 skip copy result 5 skip to end] ;; returns "hello" parse/all {ab hello cd} [thru #" " copy result to #" " to end] ;; returns "hello" | |
Pekr: 4-May-2009 | 'break is needed in Ladislav's code imo because after first match of "B" you want to escape (break from) repetitive 'any block, and continue your processing with furhter rules (which is not the case with Ladislav's example, but is the case with your example, where 'copy followed. If there would be no break, after matching "B", the rule would still succeed, because if there is no "B", then there is always "skip option, which is always valid until the end of the script. So actually without the 'break, this 'any block would 'skip till the end of input string is reached ... | |
mhinson: 13-May-2009 | Hi, I have been puzzeling over this all evening & would love a few tips please. I am trying to write a single parse rule that will extract the first number before the "/" in each case, but my logic must be faulty I think. digit: charset [#"0" - #"9"] data1: {random 10/2} data2: {2/33-35,2/48} parse/all data1 [ some [[h: 1 2 digit :h copy result to "/" thru end] | skip]] result parse/all data2 [ some [[h: 1 2 digit :h copy result to "/" thru end] | skip]] result | |
Group: Parse ... Discussion of PARSE dialect [web-public] | ||
BrianH: 22-Aug-2005 | parse/all data [any [to "*" a: skip b: to "*" c: skip d: :a (change/part a rejoin ["<strong>" copy/part b c "</strong>"] d)] to end] | |
BrianH: 22-Aug-2005 | markup-chars: charset "*~" non-markup: complement markup-chars tag1: ["*" "<strong>" "~" "<i>"] tag2: ["*" "</strong>" "~" "</i>"] parse/all data [ any non-markup any [ ["*" a: skip b: to "*" c: skip d: | "~" a: skip b: to "~" c: skip d: ] :a ( change/part a rejoin [ select tag1 copy/part a b copy/part b c select tag2 copy/part c d ] d ) any non-markup ] to end ] | |
BrianW: 22-Aug-2005 | Here's what I have right now: markup-chars: charset "*_@" non-markup: complement markup-chars inline-tags: [ "*" "strong" "_" "em" "@" "code" ] markup-rule: [ any non-markup any [ [ a: "*" b: to "*" c: skip d: | a: "_" b: to "_" c: skip d: | a: "@" b: to "@" c: skip d: ] :a ( change/part a rejoin [ "<" select inline-tags copy/part a b ">" copy/part b c "</" select inline-tags copy/part a b ">" ] d ) any non-markup ] to end ] parse text markup-rule | |
BrianW: 22-Aug-2005 | okay, here's a slightly tweaked version that uses a multichar markup tag: markup-chars: charset "[*_-:---]" non-markup: complement markup-chars inline-tags: [ "*" "strong" "_" "em" "@" "code" "--" "small" ] markup-rule: [ any non-markup any [ [ a: "*" b: to "*" c: skip d: | a: "_" b: to "_" c: skip d: | a: "@" b: to "@" c: skip d: | a: "--" b: to "--" c: skip skip d: ] :a ( change/part a rejoin [ "<" select inline-tags copy/part a b ">" copy/part b c "</" select inline-tags copy/part a b ">" ] d ) any non-markup | skip ] to end ] parse/all text markup-rule | |
Graham: 11-Oct-2005 | [ copy frag n skip | copy frag to end ] | |
Ladislav: 11-Oct-2005 | or copy frag [n skip | to end] | |
Ladislav: 11-Oct-2005 | how about this one?: copy frag [n skip | to end] (frag: any [frag ""]) | |
Tomc: 11-Oct-2005 | split-text: func [txt [string!] n [integer!] /local frag fraglet bl frag-rule bs ws ][ ws: charset [#" " #"^-" #"^/"] bs: complement ws bl: copy [] frag-rule: [ any ws [copy frag [n skip] [opt[copy fraglet some bs (insert tail frag fraglet)] ] |[copy frag to end] (insert tail bl frag) ] parse/all txt [some frag-rule] bl ] | |
Ladislav: 11-Oct-2005 | >> n: 5 parse "" [copy frag [n skip | to end] (frag: any [frag ""])] == true >> frag == "" | |
Ladislav: 11-Oct-2005 | split-text: func [ txt n /local frag result bl stop-rule ][ bl: copy [] result: copy "" stop-rule: none end-rule: [to end (stop-rule: [end skip])] frag-rule: [ copy frag [n skip | end-rule] (frag: any [frag ""] print frag append result frag) copy frag [to #" " | end-rule] (frag: any [frag ""] print frag append result frag append bl copy result clear result)] parse/all txt [some [frag-rule stop-rule]] bl ] | |
Tomc: 11-Oct-2005 | split-text: func [txt [string!] n [integer!] /local frag fraglet bl frag-rule bs ws ][ ws: charset [#" " #"^-" #"^/"] bs: complement ws bl: copy [] frag-rule: [ any ws copy frag [ [1 n skip opt[copy fraglet some bs] ] | to end skip ] (all [fraglet join frag fraglet] insert tail bl frag print frag ) ] parse/all txt [some frag-rule] bl ] | |
Ladislav: 16-Oct-2005 | Gabriele: the [copy frag [n skip | to end] (insert tail result any [frag""])] looks too complicated for the PARSE setting words to NONE justification, I would at least prefer to add it to the ticket as an example. | |
Volker: 23-Oct-2005 | i use "a" any[ "b" | "c" | skip ] to end Even slower and less elegantly, but works. | |
Volker: 23-Oct-2005 | Maybe i used this? parse s ["a" some[ "be" break | "ce" break | skip] p: to end] if nothing is found, it skips to the end. returns true, but if you require something after it, that fails (because already at end). | |
Volker: 31-Oct-2005 | or "end skip". with break the parsed part counts as success. with end skip it counts as failure and backtracks. | |
Volker: 31-Oct-2005 | the general way: rule: [ ( dummy-rule: [] if not ok? [ dummy-rule: [end skip] ) dummy-rule ] | |
BrianH: 1-Nov-2005 | I didn't do a really useful example, just one to demonstrate the current way of faking the behavior. Example: [if (test) | ...] Fix: [(unless test [dummy: [end skip]]) dummy | ...] | |
BrianH: 1-Nov-2005 | See, this is why I wanted that if clause. It's so easy to mess up the workaround. Fix: [(dummy: unless test [[end skip]]) dummy | ...] | |
Volker: 4-Nov-2005 | should work like thru. "any non-caret" is like "to caret", then skipping it is like "thru caret". without caret it would go to end, and then the final skip fail. | |
BrianH: 27-Jun-2006 | You can drop one charset by changing [non-alpha | end] to [alpha end skip | end | none] . | |
BrianH: 27-Jun-2006 | No, that would break out of the enclosing all loop. The end skip will always fail and proceed to the next alternate. | |
Tomc: 28-Jun-2006 | capital: charset {ABCDEFGHIJKLMNOPQRSTUVWXYZ} ws: charset { ^/^-} latipac: difference complement capital ws sub-rule: [ some capital there: [ws | end] (all[ 4 < length? copy/part :here :there insert :there "</strong>" insert :here "<strong>" there: skip :there 17] ) ] rule: [ any latipac [ some ws here: sub-rule ]|[skip there:] :there ] parse/all/case txt [here: opt sub-rule some rule] | |
Graham: 1-Jul-2006 | Trying to do some macro expansion in text ... This is not working :( expand-macros: func [tmp [string!] macros [block!] /local white-rule rule len lexp ] [ white-rule: charset [#" " #"^/"] foreach [macro expansion] macros [ len: length? macro lexp: length? expansion rule: compose/deep copy [ [ to here: white-rule (macro) white-rule ( change/part here expansion len ?? macro) lexp skip ] to end ] parse/all tmp [some [rule]] ] tmp ] | |
BrianH: 1-Jul-2006 | expand-macros: func [data [string!] macros [block!] /local whitespace macro-rule macro here there ] compose [ whitespace: (charset " ^/") macro-rule: make block! length? macros foreach [macro expansion] macros [ macro-rule: insert insert macro-rule macro '| ] macro-rule: head remove back macro-rule parse/all data [some [ here: copy macro macro-rule there: [whitespace | end] ( there: change/part here select/skip macros macro 2 there ) :there | skip ]] macro-rule: none data ] | |
BrianH: 1-Jul-2006 | expand-macros: func [data [string!] macros [block!] /local whitespace macro-rule macro here there ] compose [ whitespace: (charset " ^/") macro-rule: make block! length? macros foreach [macro expansion] macros [ macro-rule: insert insert macro-rule macro '| ] macro-rule: head remove back macro-rule parse/all data [some [ here: copy macro macro-rule there: [whitespace | end] ( there: change/part here select/skip macros macro 2 there ) :there | skip ]] macro-rule: none data ] | |
BrianH: 1-Jul-2006 | expand-macros: func [data [string!] macros [block!] /local whitespace macro-rule macro expansion here there ] compose [ whitespace: (charset " ^/") macro-rule: make block! 2.5 * length? macros foreach [macro expansion] macros [ macro-rule: insert macro-rule compose [here: (macro) there: [whitespace | end] '|] ] macro-rule: head remove back macro-rule parse/all data [some [ macro-rule ( macro: copy/part here there there: change/part here select/skip macros macro 2 there ) :there | skip ]] macro-rule: none data ] | |
BrianH: 1-Jul-2006 | expand-macros: func [data [string!] macros [block!] /local whitespace macro-rule macro expansion here there ] compose [ whitespace: (charset " ^/") macro-rule: make block! 2.5 * length? macros foreach [macro expansion] macros [ macro-rule: insert macro-rule compose [here: (macro) there: [whitespace | end] |] ] macro-rule: head remove back macro-rule parse/all data [some [ macro-rule ( macro: copy/part here there there: change/part here select/skip macros macro 2 there ) :there | skip ]] macro-rule: none data ] | |
BrianH: 1-Jul-2006 | expand-macros: func [data [string!] macros [block!] /local whitespace macro-rule macro expansion here there ] compose [ whitespace: (charset " ^/") macro-rule: make block! 2.5 * length? macros foreach [macro expansion] macros [ macro-rule: insert macro-rule compose [here: (macro) there: [whitespace | end] |] ] macro-rule: head remove back macro-rule parse/all data [some [ macro-rule ( macro: copy/part here there there: change/part here select/skip macros macro 2 there ) :there | thru whitespace ] to end] macro-rule: none data ] | |
BrianH: 1-Jul-2006 | ; Now whitespace is dealt with expand-macros: func [data [string!] macros [block!] /local whitespace macro-rule macro expansion here there ] compose [ whitespace: (charset " ^/") macro-rule: make block! 2.5 * length? macros foreach [macro expansion] macros [ macro-rule: insert macro-rule compose [here: (macro) there: [whitespace | end] |] ] macro-rule: head remove back macro-rule parse/all data [some [any whitespace [ macro-rule ( macro: copy/part here there there: change/part here select/skip macros macro 2 there ) :there | to whitespace ]] to end] macro-rule: none data ] | |
BrianH: 1-Jul-2006 | expand-macros: func [data [string!] macros [block!] /local ws non-ws macro-rule macro expansion here there ] compose [ ws: (charset " ^/") non-ws: (complement charset " ^/") macro-rule: make block! 2.5 * length? macros foreach [macro expansion] macros [ macro-rule: insert macro-rule compose [here: (macro) there: [ws | end] |] ] macro-rule: head remove back macro-rule parse/all data [some [any ws [ macro-rule ( macro: copy/part here there there: change/part here select/skip macros macro 2 there ) :there | some non-ws ]] to end] macro-rule: none data ] | |
Pekr: 19-Jul-2006 | REBOL [] template: { <b><!--[mark-x]-->Hello x!<!--/[mark-y]--></b> <b><!--[mark-y]-->Hello y!<!--/[mark-y]--></b> <b><!--[mark-z]-->Hello z!<!--/[mark-z]--></b> <b><!--[mark-w]-->Hello w!<!--/[mark-w]--></b> } parse/all template [ some [ thru "<!--[" copy mark to "]-->" "]-->" start: copy text to "<!--/[" end: "<!--/[" mark "]-->" (print text) | skip ] ] halt | |
Pekr: 19-Jul-2006 | this one works better for me: parse/all template [ some [ thru "<!--[" copy mark to "]-->" "]-->" start: copy text to "<!--/[" end: "<!--/[" [mark "]-->" (print text) | (print ["not found end of: " mark]) :start] | skip ] ] | |
Anton: 4-Oct-2006 | string: "<good tag><bad tag><other tag><good tag>" entity: "<ENTITY>" parse/all string [ any [ to "<" start: skip to ">" end: skip (if not find copy/part start end "good tag" [ change/part start entity 1 ; fix up END (for when your entity is other than a 1-character long string) end: skip end (length? entity) - 1 change/part end entity 1 ; fix up END again end: skip end (length? entity) - 1 ]) :end skip ] to end ] string ;== {<good tag><ENTITY>bad tag<ENTITY><ENTITY>other tag<ENTITY><good tag>} | |
Anton: 4-Oct-2006 | string: "<good tag><bad tag> 3 > 5 <other tag><good tag with something inside>" string: " > >> < <<good tag><bad tag> 3 > 5 <other tag><good tag etc> >> > " ; (1) search for end tags >, they are erroneous so replace them ; (2) search for start tags <, if there is more than one, replace all except the last one ; (3) search for end tag >, check tag body and replace if necessary entity: "&entity;" ntag: complement charset "<>" ; non tag parse/all result: copy string [ any [ ; (1) any [ any ntag start: ">" end: ( change/part start entity 1 end: skip start length? entity ;print [1 index? start] ) :end ] ; (2) (start: none stop?: none) any [ any ntag start: "<" end: ;(print [2 mold start]) any ntag "<" ( ;print "found a second start tag" change/part start entity 1 end: skip start length? entity ;(print [2.1 mold copy/part start end]) start: none ) :end ] (if none? start [stop?: 'break]) stop? ; ok, we found at least one start tag ;(print ["OK we found at least one start tag" mold start]) :start skip ; (3) any ntag end: ">" ;(print [3 mold copy/part start end]) (if not find copy/part start end "good tag" [ ;print ["found a bad tag" mold copy/part start end] change/part start entity 1 ; fix up END (for when your entity is other than a 1-character long string) end: skip end (length? entity) - 1 change/part end entity 1 ; fix up END again end: skip end (length? entity) - 1 ]) :end skip ] to end ] result | |
Gabriele: 25-Dec-2006 | >> rules: [ [ any [ [ end break [ | [ copy value [to newline | to end] (print value) opt skip [ ] [ ] == [ any [ end break | copy value [to newline | to end] (print value) opt skip ] ] >> parse s2 rules str 1 str 2 str 3 == true | |
Gabriele: 26-Dec-2006 | joe, if you don't care about parse returning true you can just use skip (without opt, which is there for the end case) | |
Ladislav: 27-Dec-2006 | Joe: another option is to use: rules: [ any [ copy value [to newline | to end] (print value) skip ] to end ] | |
Ladislav: 27-Dec-2006 | but, as Gabriele said, that is equivalent to: rules: [ any [ copy value [to newline | to end] (print value) skip ] ] if you ignore the parse result | |
BrianH: 27-Dec-2006 | to end skip will always fail. move the skip after the to newline. | |
Oldes: 19-Jan-2007 | Isn't this a bug? >> b: "1234^@567" parse/all b [copy i to {^@} 1 skip b: to end] probe i probe b 1234 567 BUT: >> b: "1234^@567" parse/all b [copy i to #{00} 1 skip b: to end] probe i probe b 1234 1234^@567 | |
Volker: 19-Jan-2007 | >> b: "1234^@567" parse/all b [copy i to "^(0)" 1 skip b: to end] == true >> i == "1234" | |
Maxim: 13-Apr-2007 | symbol: charset [#"a" - #"z" #"A" - #"Z" #"0" #"9" "_-?!*+~"] nstr: "...aa.....a.....a.....h." parse/all nstr [ some [ symbol | end skip | [ here: ( probe here either none? here/1 [print nstr print "!!" ][print here/1 print nstr remove here here: back here]) ; :here skip ] ;:here ] ] probe nstr | |
Ladislav: 13-Apr-2007 | Max: ...symbol | end skip | ... does not have much sense, since it is equivalent to just ...symbol | ... | |
Ladislav: 13-Apr-2007 | rule: [(next-rule: unless result-of-expression [[end skip]]) next-rule] | |
Ladislav: 13-Apr-2007 | see this: >> rule: [(next-rule: unless result-of-expression [[end skip]]) next-rule] == [(next-rule: unless result-of-expression [[end skip]]) next-rule] >> result-of-expression: false == false >> parse "" rule == false >> result-of-expression: true == true >> parse "" rule == true | |
Ladislav: 28-Jun-2007 | this is possible, but my guess, that Steeve would call it ugly too: >> once-only: func [rule] [use [rule'] copy/deep [rule': :rule [rule' (rule': [end skip])]] ] >> rule: [(a': once-only a b': once-only b c': once-only c) 3 [a' | b' | c']] == [(a': once-only a b': once-only b c': once-only c) 3 [a' | b' | c']] | |
Geomol: 28-Jun-2007 | Ladislav, that's not ugly, it's beautiful! :-) I have a question though. Do you need the skip at the end of once-only? Wouldn't it work just with rule': [end] | |
Ladislav: 28-Jun-2007 | John: [end skip] is a rule that surely fails, while [end] may succeed (at end) | |
Geomol: 28-Jun-2007 | I see. That's also why my block parsing give false result with less input. So for block-parsing, it should be: >> once-only: func [:rule] [use [rule'] copy/deep [rule': :rule [rule' (rule': [end skip])]]] | |
Geomol: 28-Jun-2007 | >> once-only: func [rule] [use [rule'] copy/deep [rule': :rule [rule' (rule': [end skip])]]] >> rule: [(a': once-only 'a b': once-only 'b c': once-only 'c) 3 [a' | b' | c']] >> parse [a b c] rule ** Script Error: Invalid argument: a | |
Steeve: 28-Jun-2007 | Once (again) Rebol is amazing, i think i found a simple and elegant dialect Currently, it's not allowing recursive once usage, but it's obvious to do with a stack. take: func [r] [n: 0 once/1: (length? r) + 1 / 3 once/2/2: r replace/all r '.. '.] .: [(n: n + 1)] ..: [(n: n + 1) end skip] once: [0 [(if n > 0 [poke once/2/2 n - 1 * 3 + 1 '..] n: 0) []]] rule: [. "a" | . "b" | . "c"] parse "CBA" [ (take rule) once] == true parse "BAC" [ (take rule) once] == true parse "CBA" [ (take rule) once] == true parse "BBC" [ (take rule) once] == true parse "CA" [ (take rule) once] == false parse "CABA"[ (take rule) once] == false rule2: [. "a" | . "a" | . "b" | . "c"] parse "CABA"[ (take rule2) once] == true | |
Tomc: 29-Jun-2007 | do rules: [ set 'a "first rule " set 'b "second rule " set 'c "third rule " ] rule: [ [end (if empty? erode[here: back tail :here]) :here skip]| [here: erode there: ( all[ token: copy/part :here :there word: find rules token word: first back word remove/part find erode word 2 ] all[empty? erode not tail? there insert/only erode [] there: tail there] )] :there rule ] data: "first rule second rule third rule " erode: [ a | b | c | a] parse/all data rule | |
Group: Linux ... [web-public] group for linux REBOL users | ||
Ladislav: 9-Apr-2007 | Max, why don't you use LOAD in PARSE, if you want to? Example: rule: [ (result: make block! 0) any [ [ ; trying to load pos: skip ( next-rule: either error? try [ set [value pos] load/next pos ] [[end skip]] [[:pos]] ) next-rule | ; load didn't succeed, using something else copy value skip ] (insert/only tail result get/any 'value) ] ] >> parse "1 2 a, 3" rule == true >> result == [1 2 "a" "," 3] | |
Ladislav: 9-Apr-2007 | twist of redefining a rule... - that is just to "tell PARSE" whether the paren operation succeeded or not - [end skip] is failure | |
Group: !Readmail ... a Rebol mail client [web-public] | ||
Graham: 17-May-2005 | From Didier ; decode ISO-8859-1 / ASCII-US encoded text decode-iso8859: func [str /local ascii non-ascii char text emit quoted-printable encoded-word res b e] [ emit: func [v][append res v] ascii: charset [#" " - #"^(7f)"] non-ascii: complement ascii text: exclude union ascii non-ascii charset ["="] char: exclude ascii charset ["?_=^-"] encoded-word: [ "=?" ["ISO-8859-1" | "us-ascii"] [ "?q?" some quoted-printable | "?b?" b: to "?" e: (emit to-string debase copy/part b e) ] "?=" ] quoted-printable: [ "_" (emit #" ") | b: some char e: (emit copy/part b e) | b: "=" (emit do rejoin [ {#"^^(} second b third b {)"} ]) 2 skip ] res: make string! length? str parse/all str [any [encoded-word | "=" (emit #"=") | "^/ " | b: some text e: (emit copy/part b e)] to end] res ] | |
Group: Announce ... Announcements only - use Ann-reply to chat [web-public] | ||
eFishAnt: 2-May-2006 | Visit http://www.TGD-Consulting.de/Download.htmland take a look at the final release of Hex-It!. (I posted on behalf of Dirk Weyand, since he cannot reach AltME) Hex-It! is a small but powerful hex-editor. You can use this tool to analyse or alter the "fingerprints" for any kind of files. Known first as a contribution to the REBOL Demo 2006 contest, the final release with enhanced features is available now. Features of Hex-It! v1.2.0: --------------------------- * cross platform hex-editor * free "save-feature" for small files sized lesser 15 KB, to edit larger files purchase a license-key that unlocks this limitation * enhanced spot navigation with mouse scroll-wheel support * non blocking file access * support of large files (a maximum chunk of 1MB file-data is only held in memory at once) Some notes and useful tips & tricks on the usage of Hex-It!: ------------------------------------------------------------ - Modifications of files were automatically saved on exit, if you load another file or if a different chunk of the same file is selected. - Byte selection: + Select a byte with a left mouse button (LMB) click on the hexadecimal values to the left. The byte is highlighted then. + If a byte is selected, either use the cursor keys or the scroll-wheel of the mouse to scroll through the bytes of the file. + Change a selected byte with plus (+) & minus (-) or just enter its new value. Single characters, three digit numbers or single hexadecimal values are valid. + Use the right mouse button (RMB) to deselect a highlighted byte. - Spot-navigation: + The spot specifies the index/position of a byte in the file. If no byte is selected it shows the position of the top left byte displayed. + Enter a number to set directly the spot to a byte-position. + Skip a certain amount of bytes relative to the current spot by using plus (+) & minus (-), e.g. "+10000" skips 10000 bytes forward and "-1000" skips 1000 bytes backwards. + Skip to end of file: Click with the RMB on the arrow-down Spot-button or use the "End"-Key. + Skip to first byte of file: Click with the RMB on the arrow-up Spot-button or use the "Home"-Key. - Seek: + ASCII- or Hex-Strings are valid queries. + LMB click on the "Seek"-button seeks from the current position. + RMB click on the "Seek"-button seeks from the beginning of the file. Please note, that the license of this release is not BSD like anymore. | |
Group: Rebol School ... Rebol School [web-public] | ||
Geomol: 6-Feb-2009 | The second argument to parse can be a string, and then parse split up the first argument, or the second argument can be a block of parsing rules. out is just my output block. So the parsing rules go: 1) first any of a sub-block of sub-rules 2) sub-block copy the input string to a point, where two newlines are found, the result in the variable: arg 3) the paranthesis is evaluated (as normal REBOL code), and it append arg (the part of the string, we just copied) to the variable out 4) the parser then skip any number of newlines (2, 3 or more) 5) when the sub-rules are not valid any longer, the input string is copied till the end (and appended to out as before) | |
Group: rebcode ... Rebcode discussion [web-public] | ||
BrianH: 14-Oct-2005 | (Thinking out loud) It occurs to me that computed branches would be a lot easier if you could reference the target values in your code, so that you have something to compute with. If the offsets were absolute you could just assign them to the label words (something that could be done in the first pass of the assembler rewrite of the branch statements). Relative offsets could be calculated pretty easily if you had something like a HERE opcode that would assign the current position to a variable that could be used soon afterwards to calculate the relative offset. For that matter, the HERE opcode could perform the assignment of the original label as well, and even be accomplished by a rewrite rule in the branch fixup pass of the assembler. Here's my proposal for a HERE assembler directive. No native opcodes would need to be added - this would be another directive like label. This directive could be used to set the target values to words for later computation. Assuming BRAW stays relative and no absolute computed branch is added, it could also be used in computations to convert from absolute to relative offsets. This would be sufficient to make computed branches practical. - A new directive HERE, taking two arguments, a word and a literal integer. It would set the word to the position of the HERE directive, plus an offset specified in the second parameter. The offset would need to be a literal because the calculation would be performed ahead of time by the assembler - 0 would mean no offset. If you don't want to reset the position every time you branch to the word use an offset of 3. Resetting the word after every branch would allow its use as a temporary in absolute-to-relative calculations, but that would only be an advantage until the JIT or optimizer is implemented - the choice would be up to the developer. Having a mandatory second argument is necessary for reasons that will become clear later. - The HERE directive would be rewritten away in the fix-bl function of the assembler like this: REBOL [] ; So I could use SciTE to write this message fix-bl: func [block /local labels here label] [ labels: make block! 16 block-action: :fix-bl if debug? [print "=== Fixing binding and labels... ==="] parse block [ some [ here: subblock-rule (here/1: bind here/1 words) | 'label word! (here/1: bind here/1 words insert insert tail labels here/2 index? here) | ; Beginning of the added code 'here word! integer! ( here/1: bind 'set words ; This is why HERE needs two arguments here/3: here/3 + index? here ; Offset from position of this directive if (here/3 < 1) or (here/3 > 1 + length? block) [ error/with here "Offset out of bounds:" ] ) ; End of the added code | opcode-rule (here/1: bind here/1 words) | skip (error here) ] ] parse block [ some [ here: ['bra word! | 'brat word! | 'braf word!] ( if not label: select labels here/2 [error/with here "Missing label:"] here/2: label - index? here ) | opcode-rule | skip (error here) ] ] ] | |
Group: Tech News ... Interesting technology [web-public] | ||
Volker: 11-May-2007 | text: { 10-Mar-2007 $12,002.34 "Home Hardware" "Tile Saw" 1--Mar-2007 $12002.34 "Home Hardware" "Tile Saw" } parse text blk-rule: [ some [ str: newline | #";" [thru newline | to end] new: (probe copy/part str new) | [#"[" | #"("] blk-rule | [#"]" | #")"] break | skip ( either attempt [ set [value new] load/next str ] [ probe :value ] [ new: find str " " print ["GIBBERISH" copy/part str new] ] ) :new ] ] | |
Group: !Cheyenne ... Discussions about the Cheyenne Web Server [web-public] | ||
Graham: 14-Jul-2007 | and from Cheyenne ## Error in [uniserve] : On-received call failed with error: make object! [ code: 305 type: 'script id: 'invalid-arg arg1: none arg2: none arg3: none near: [parse/all data [ some [ s: to bound e: ( if e <> s [ either wrt? [ insert/part tmp/port s skip e -2 ] [ insert/part tail req/in/content s e ] ] ) s: bound [ "--" to end s: break | thru crlfcrlf e: ( insert/part tail req/in/content s e if wrt?: to logic! find/part s "Content-Type" e [ append tmp/files name: make-tmp-filename repend req/in/content [mold name crlf] if tmp/port [close tmp/port] tmp/port: open/mode name [ binary direct no-wait write new ] ] ) ] ] ] tmp/buffer: either ] where: 'process-content ] ! | |
Dockimbel: 20-Dec-2007 | HOW-TO make Cheyenne work with PHP for non-Windows OS The purpose of the following patch is to make FastCGI in PHP work the same on all OSes. 1) If you have PHP v5.2.1 or higher with sources, you can skip 2) & 3) else : 2) Download latest PHP sources from http://www.php.net/downloads.php 3) Untar the archive anywhere yo want 4) Go to PHP install folder 5) Patching PHP source : Open a REBOL console, then : ;---- cut'n paste the following code in REBOL's console ---- patch-php: has [buffer pos][ target: %sapi/cgi/fastcgi.c if none? attempt [buffer: read target][ print "unable to find the file to patch!!" exit ] either parse buffer [ thru "int fcgi_accept_request(" to "if (req->fd >= 0) {" pos: to end ][ insert pos "^/^-^-^-^-break;^/^-^-^-^-" write target buffer print "patch applied." ][ print "failed to locate the line to patch!!" ] ] patch-php ;---- end of code ---- 6) Once the patch is applied : > ./configure --enable-fastcgi > make > sudo make install 7) Check if everything is ok : > php-cgi -h ... you should see a -b option listed meaning you got proper FastCGI support. If it fails (occured on OSX), try with a full path instead : > /usr/local/bin/php-cgi -h 8) Edit Cheyenne's config file (httpd.cfg) to set the correct option in the PHP section. Non-Windows users have to also set the new 'delay option. | |
Will: 21-May-2008 | impressed! 8) I finally gave another try at php support in cheyenne and after patching fastcgi.c as suggested it now works like a charm. If you are on os x and use macports, here is a way to patch and compile: sudo port install php5 +mysql5 +fastcgi sudo port uninstall php5 cd /opt/local/var/macports/distfiles/php5/ sudo tar -xjf php-5.2.6.tar.bz2 >> run patch below tar -cjf php-5.2.6.tar.bz2 php-5.2.6 sudo port install php5 +mysql5 +fastcgi checksum.skip=yes copy of Dockimbel's patch with path fixed for this example ;---- cut'n paste the following code in REBOL's console ---- patch-php: has [buffer pos][ target: %php-5.2.6/sapi/cgi/fastcgi.c if none? attempt [buffer: read target][ print "unable to find the file to patch!!" exit ] either parse buffer [ thru "int fcgi_accept_request(" to "if (req->fd >= 0) {" pos: to end ][ insert pos "^/^-^-^-^-break;^/^-^-^-^-" write target buffer print "patch applied." ][ print "failed to locate the line to patch!!" ] ] patch-php ;---- end of code ---- | |
Robert: 12-Jun-2009 | I have a problem, that after some running time Cheyenne seems to get into an unstable state and my REST shopping-cart isn't working any longer. I got this error in the trace.log, which seems to be Cheyenne internal: 5/6-10:09:48.142823-## Error in [task-handler-40014] : Make object! [ code: 501 type: 'access id: 'not-open arg1: "Port" arg2: none arg3: none near: [parse/all current: fourth entry [ any [ end break | "#[" copy value to #"]" skip ( append out reform [ " prin any [pick cat" locale/id? value mold value #"]" ] ) | "<%" [#"=" (append out " prin ") | none] copy value [to "%>" | none] 2 skip ( if value [repend out [value #" "]] ) | s: copy value [any [e: "<%" :e break | e: "#[" :e break | skip]] e: ( append out reform [" txt" index? s offset? s e #" "] ) ] ]] where: 'confirm ] ! 5/6-23:01:46.501455-## Error in [task-handler-40014] : Make object! [ code: 501 type: 'access id: 'not-open arg1: "Port" arg2: none arg3: none near: [unless no-lang [ id: locale/lang locale/set-default-lang ] out: make ] where: 'confirm ] ! |
1 / 211 | [1] | 2 | 3 |